package edu.gatech.asthma.activity;

import edu.gatech.asthma.R;
import edu.gatech.asthma.database.DBAdapter;
import edu.gatech.asthma.ui_support.HelpMenuHelper;
import edu.gatech.asthma.ui_support.ProfileCustomizer;
import edu.gatech.asthma.ui_support.ResourceHelper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * Activity that allows user to enter subjective feeling before continuing to breathing test
 */
public class SubjectiveTestActivity extends Activity {
	
	int identifier = -1;
	DBAdapter database;
	ProfileCustomizer customizer;
	int chosen = -1; //feeling selected
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_subjective);
        
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
        	identifier = extras.getInt("ID");
        }
        database = new DBAdapter(this);
        database.open();
        customizer = new ProfileCustomizer(this,this.findViewById(android.R.id.content),database,identifier);
        customizer.setCustomizations();
    }
	
	
	/**
	 * Called when user clicks any of the subjective face buttons on the screen
	 * @param v The View (ImageButton) that was clicked
	 */
	public void feelingSelected(View v) {
		chosen = Integer.parseInt((String) v.getTag()); //corresponds to the image selected
		
		//make sure all other buttons are "off"
		((ImageView) findViewById(R.id.subjective0)).setColorFilter(getResources().getColor(R.color.white));
		((ImageView) findViewById(R.id.subjective1)).setColorFilter(getResources().getColor(R.color.white));
		((ImageView) findViewById(R.id.subjective2)).setColorFilter(getResources().getColor(R.color.white));
		((ImageView) findViewById(R.id.subjective3)).setColorFilter(getResources().getColor(R.color.white));
		((ImageView) findViewById(R.id.subjective4)).setColorFilter(getResources().getColor(R.color.white));
		((ImageView) findViewById(R.id.subjective5)).setColorFilter(getResources().getColor(R.color.white));
		
		//set background and tint according to user'a accent color
		((ImageView) v).setColorFilter(getResources().getColor(ResourceHelper.getColor("accent_color"+database.getProfile(identifier).getAccentColor())));
	}
	
	/**
	 * Called when user clicks the submit button on this screen
	 * @param v The View (Button) that was clicked
	 */
	public void onSubmitClicked(View v) {
		if (chosen == -1) { //nothing selected
			Toast toast = Toast.makeText(this, 
					getResources().getString(R.string.subjective_blank), Toast.LENGTH_LONG);
			toast.show();
		}
		else {
			//TODO save in database
			Intent i = new Intent(SubjectiveTestActivity.this, BreathingTestActivity.class);
	    	i.putExtra("ID", identifier);
	    	SubjectiveTestActivity.this.startActivity(i);
		}
	}
	
	/**
	 * User clicked the help button on this screen
	 * @param v ImageView clicked
	 */
	public void helpButtonClicked(View v) {
		HelpMenuHelper.displayHelpMessage(this);
	}
}